package vo;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@NamedQueries({ 
	@NamedQuery(name = "Opinion.findAll", query = "select e from Opinion e order by created_at"),
    @NamedQuery(name = "Opinion.findTotalCount", query = "select count(*) from Opinion e order by created_at"),

    @NamedQuery(name = "Opinion.findByPaperId", query = "select e from Opinion e where paper.id=? order by created_at"),
	@NamedQuery(name = "Opinion.findTotalCountByPaperId", query = "select count(*) from Opinion e where paper.id=? order by created_at"),

	@NamedQuery(name = "Opinion.findByType", query = "select e from Opinion e where opinionType.id=? order by created_at"),
	@NamedQuery(name = "Opinion.findTotalCountByType", query = "select count(*) from Opinion e where opinionType.id=? order by created_at"),
	
	@NamedQuery(name = "Opinion.findByKeyword", query = "select e from Opinion e where text like ? order by created_at"),
	@NamedQuery(name = "Opinion.findTotalCountByKeyword", query = "select count(*) from Opinion e where text like ? order by created_at"),
	
	@NamedQuery(name = "Opinion.findByTypeKeyword", query = "select e from Opinion e where opinionType.id=? and text like ? order by created_at"),
	@NamedQuery(name = "Opinion.findTotalCountByTypeKeyword", query = "select count(*) from Opinion e where opinionType.id=? and text like ? order by created_at")
	
})
@Table(name = "opinion")
public class Opinion extends BaseEntity {

	@JoinColumn(name = "paper_id")
	@ManyToOne(fetch = FetchType.LAZY)
	private Paper paper;

	@JoinColumn(name = "type")
	@ManyToOne(fetch = FetchType.LAZY)
	private OpinionType opinionType;

	private String text;

	@Column(name = "created_at")
	String createdAt;

	public Paper getPaper() {
		return paper;
	}

	public void setPaper(Paper paper) {
		this.paper = paper;
	}


	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getCreatedAt() {
		return createdAt;
	}

	public void setCreatedAt(String createdAt) {
		this.createdAt = createdAt;
	}

	public OpinionType getOpinionType() {
		return opinionType;
	}

	public void setOpinionType(OpinionType opinionType) {
		this.opinionType = opinionType;
	}


}
